package cn.com.fuhuitong.base

import android.content.Context
import android.view.View
import android.view.ViewGroup
import cn.com.fuhuitong.entity.EmptyState
import cn.com.fuhuitong.entity.MainBean
import cn.com.fuhuitong.main.base.RecyclerViewHolder
import com.alibaba.android.vlayout.LayoutHelper
import cn.com.fuhuitong.R
import cn.com.fuhuitong.main.ItemViewType
import kotlinx.android.synthetic.main.fragment_loading_error.view.*

/**
 *空布局适配器
 * */
enum class VT(value: Int) {
    VIEW_EMPTY(0)
}

class EmptyViewAdapter(
    private val mContext: Context, private val mHelper: LayoutHelper
) : BaseDelegateAdapter<MainBean<EmptyState, EmptyContent>>(
    mContext = mContext,
    mHelper = mHelper,
    mLayoutId = R.layout.fragment_loading_error,
    mItemViewType = ItemViewType.EMPTY
) {

    var recyclerViewWidth: Int = 0
    var recyclerViewHeight: Int = 0

    init {
        addChildClickViewIds(R.id.text_empty_execute)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
        recyclerViewWidth = parent.width
        recyclerViewHeight = parent.height
        return super.onCreateViewHolder(parent, viewType)
    }

    override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        val itemView: View = holder.itemView
        itemView.layoutParams =
            ViewGroup.LayoutParams(recyclerViewWidth, recyclerViewHeight)
        val mainBean = data[position]
        if (mainBean.type == EmptyState.START) {
            itemView.progress_empty.visibility = View.VISIBLE
            itemView.linear_empty.visibility = View.GONE
        } else {
            itemView.linear_empty.visibility = View.VISIBLE
            itemView.progress_empty.visibility = View.GONE
        }
        itemView.text_empty_message.text = mainBean.data?.message
        itemView.text_empty_execute.text = mainBean.data?.execute
//        if (mainBean.data?.isVisibility == true) {
//            itemView.text_empty_execute.visibility = View.GONE
//        } else {
//            itemView.text_empty_execute.visibility = View.VISIBLE
//        }
    }
}

data class EmptyContent(
    var execute: String = "重新加载",
    var message: String = "暂无数据"
)